package semantic.rules.walk

import syntax.{CNonTerminal, CTerminal, CGrammar, CASTNode}
import scala.collection.mutable.Buffer
import utils.data.CTree
import semantic.COperations._
import CGrammar._
import lexis.CLexemeType
import semantic.rules.CRuleException

object CWalkRuleEqNeqGteGtLteLt extends CWalkRule
{
    override val categories:Seq[CNonTerminal] = CComparingExpression :: Nil

    override def post(node:CASTNode)(implicit tree:CTree[CASTNode], code:Buffer[String]) = node().secondChild.handle(sc => sc.category.name match
    {
        case CLexemeType.EQ.name => code += EQ
        case CLexemeType.NEQ.name => code += NEQ
        case CLexemeType.GTE.name => code += GTE
        case CLexemeType.GT.name => code += GT
        case CLexemeType.LTE.name => code += LTE
        case CLexemeType.LT.name => code += LT
        case nm => CRuleException(CRuleException.WRONG_NODE_TYPE(nm))
    })
}
